package cn.parllay.dingdangproject.service;

import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;

import io.netty.channel.Channel;
import io.netty.channel.socket.SocketChannel;
/**
 * @ClassName:  NettyChannelMap   
 * @Description:map 存放  Channel
 * @author: JiangShuai 
 * @date:   2018年1月11日 下午3:00:34     
 * @Copyright: 2018 dingdian.parllay.cn Inc. All rights reserved. 
 * 注意：本内容仅限于叮当一下(北京)信息技术有限公司内部传阅，禁止外泄以及用于其他的商业目
 */
public class NettyChannelMap {
	
	//定义map存放Channel
	private static Map<String,SocketChannel> channelMap=new ConcurrentHashMap<String, SocketChannel>();

    public static void add(String clientId,SocketChannel socketChannel){  
    	channelMap.put(clientId,socketChannel);
    }
    public static Channel get(String clientId){
       return channelMap.get(clientId);
    }
    
	public static void remove(SocketChannel socketChannel){
    	for (Map.Entry<String, SocketChannel> entry:channelMap.entrySet()){  
            if (entry.getValue()==socketChannel){  
            	channelMap.remove(entry.getKey());  
            }
        } 
    }
	
	public static void removeClientId(String clientId){
        channelMap.remove(clientId);
    }
    
    public static int getSize(){
    	return channelMap.size();
    }
    
    public static Set<String> getKeys(){
    	return channelMap.keySet();
    }
 
}
